﻿namespace NetFx.SMIL.References
{
  using System;
  using System.Text;
  using System.Collections;
  using System.Collections.Generic;

  using System.Reflection;
  using System.Reflection.Emit;
  using System.Runtime.InteropServices;

  using System.Diagnostics;
  using System.Diagnostics.CodeAnalysis;
  using System.Diagnostics.SymbolStore;
  using System.Security;
  using System.Security.Permissions;

  using NetFx.MSIL;

  /// <summary>
  /// 标号组的引用。
  /// </summary>
  public class LabelsRef:ReflectRef
  {
    #region Statics
    public static LabelsRef of(params string[] labels)
    {
      List<LabelRef> labs = new List<LabelRef>();
      if (labels != null)
      {
        for (int i = 0; i < labels.Length; i++)
        {
          string lab = labels[i];
          if (lab != null && lab != string.Empty)
          {
            labs.Add(LabelRef.of(lab));
          }
        }
      }
      return of(labs.ToArray());
    }
    public static LabelsRef of(params LabelRef[] labels)
    {
      return new LabelsRef(labels);
    }
    #endregion
    #region Fields
    protected List<LabelRef> lables = null;
    #endregion
    #region Properties
    /// <summary>
    /// 获取引用类型（为标号）。
    /// </summary>
    public override DefType ReflectionType
    {
      get { return DefType.Labels; }
    }
    public virtual List<LabelRef> Labels
    {
      get
      {
        return this.lables == null ? this.lables = new List<LabelRef>() :
          this.lables;
      }
    }
    public virtual List<LabelRef> ReflectInfo
    {
      get
      {
        return this.Labels;
      }
    }
    public override bool HasReflectInfo
    {
      get
      {
        return this.ReflectInfo != null;
      }
    }

    #endregion
    #region Constructors
    public LabelsRef(params LabelRef[] labels)
      : base(null) 
    {
      if (labels != null)
      {
        this.Labels.AddRange(labels);
      }
    }
    #endregion
    #region Methods
    public override string ToString()
    {
      bool first = true;

      StringBuilder builder = new StringBuilder();

      foreach (LabelRef label in this.Labels)
      {
        if (label != null)
        {
          if (!first)
          {
            builder.Append(", ");
          }
          builder.AppendFormat("{0}", label.ToString());

          first = false;
        }
      }
      return builder.ToString();
    }
    #endregion
  }
}
